<template>
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <span slot="oneRowName" slot-scope="text, record">
          <span v-if="text" class="oneRowName" :title="text">{{text}}</span>
        </span>
        <span slot="tag" slot-scope="text, record">
          <template v-if="text">
            <span class="tagSpan" v-for="(item,index) in text.split(',')">{{item}}</span>
          </template>
        </span>
      </a-table>
    </div>

</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  export default {
    name: "CompanyInteractiveList",
    mixins:[JeecgListMixin],
    components: {
        
    },
    props:{
      companyId:{
        type:String
      }
    },
    data () {
      return {
        // 表头
        columns: [
          {
            title: '新闻日期',
            align:"center",
            defaultSortOrder: 'descend',
            sorter: (a, b) => a.NewsDate - b.NewsDate,
            dataIndex: 'NewsDate'
           },
       {
            title: '新闻类型',
            align:"center",
            sorter: (a, b) => a.NewsType_Value - b.NewsType_Value,
            dataIndex: 'NewsType_Value'
           },
       {
            title: '新闻标题',
            align:"center",
            dataIndex: 'NewsTitle'
           },
       {
            title: '摘要',
            align:"center",
            dataIndex: 'Remarks'
           },
       {
            title: '链接地址',
            align:"center",
            dataIndex: 'Url',
            scopedSlots: { customRender: 'Url' },
           },
       {
            title: '新闻来源',
            align:"center",
            dataIndex: 'DataSource_Value'
           },
           
		   
        ],
        isortercompany:{
            column: 'NewsDate',
            order: 'desc',
        },
		url: {
          list: "",
       },
    }
  },
    mounted(){
      this.url.list = '/companyNews/queryRows';
      this.loadData();
    },
    methods: {
      handleTableChange(pagination, filters, sorter) {
          //分页、排序、筛选变化时触发
          //TODO 筛选
          if (Object.keys(sorter).length > 0) {
              this.isortercompany.column = sorter.field;
              this.isortercompany.order = "ascend" == sorter.order ? "asc" : "desc"
          }
          this.epagination = pagination;
          this.loadData();
      },
      loadData(){
        let param = {PageIndex:this.epagination.current,pageSize:this.epagination.pageSize,conditions:[{
          "field":'Company',
          "operator":"=",
          "value":this.companyId
        }]};
        param.orders = [{field: this.isortercompany.column,desc: this.isortercompany.order == 'desc'?true:false}]
        this.$http.postAction(this.url.list, param).then((res) => {
            if (res.status == 1) {
                this.dataSource = res.data.rows;
                this.ipagination.total = res.data.totalCount;
            }else{
                this.$message.warning(res.message)
            }
            this.loading = false;
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>